import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//引入封装好的模块
import menu from './modules/menu'
import role from './modules/role'
import user from './modules/manger'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import member from "./modules/member"
import banner from "./modules/banner"
import seck from "./modules/seck"
export default new Vuex.Store({
  state: {
    userinfo:sessionStorage.getItem('userinfo')?JSON.parse(sessionStorage.getItem('userinfo')): null
  },
  getters:{
    getUserInfo(state){
      return state.userinfo
    }
  },
  mutations: {
    REQ_USER(state,payload){
      if(payload){
        state.userinfo = payload
        //把信息进行存储
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem('userinfo')
      }
      
    }
  },
  actions: {
    //封装一个存储登录信息的行动
    changeUser({commit},payload){
      // console.log(payload,'传参');
      commit('REQ_USER',payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    cate,
    specs,
    goods,
    member,
    banner,
    seck,
  }
})
